{% extends "staff/base.html" %}
{% import 'staff/_formhelpers.html' as forms with context %}
{% import 'staff/_helpers.html' as helpers %}

{% block title %} {{ assignment.display_name }} - {{ current_course.display_name_with_semester }}{% endblock %}

{% block main %}
  <section class="content-header">
      <h1>
        {{ student.identifier }}'s {{ assignment.display_name }}
      </h1>
      <ol class="breadcrumb">
        <li><a href="{{ url_for("admin.course", cid=current_course.id) }}">
            <i class="fa fa-university"></i> {{ current_course.offering }}
        </a></li>
        <li><a href="{{ url_for('.course_assignments', cid=current_course.id) }}">
          <i class="fa fa-list"></i> Assignments</a>
        </li>
        <li> <a href="{{ url_for('.assignment', cid=current_course.id, aid=assignment.id) }}"><i class="fa fa-book"></i> {{ assignment.display_name }} </a></li>
        <li> <a href="{{ url_for('.student_view', cid=current_course.id, email=student.email) }}"><i class="fa fa-user"></i> {{ student.identifier }} </a></li>
        <li class="active"><a href="#"><i class="fa fa-inbox"></i> History </a></li>
      </ol>
  </section>

  <section class="content">
    {% include 'alerts.html' %}

      <div class="row">
        <!-- Begin assign_status -->
        <div class="col-md-3 col-sm-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">Submission Stats</h3>
                </div>

                <div class="row">
                  <div class="col-sm-12">
                    <div class="description-block border-bottom">
                      <h5 class="description-header">{{ 'Submitted' if stats['num_submissions'] > 0 else 'Not Submitted' }}</h5>
                      <span class="description-text">Submission Status</span>
                    </div>
                  </div>
                </div>
                {% if stats['current_q'] %}
                <div class="row">
                  <div class="col-sm-12">
                    <div class="description-block border-bottom">
                      <h5 class="description-header">{{ stats['current_q'] }}</h5>
                      <span class="description-text">Current Question</span>
                    </div>
                  </div>
                </div>
                {% endif %}
                {% if stats['attempts'] %}
                <div class="row">
                  <div class="col-sm-12">
                    <div class="description-block border-bottom">
                      <h5 class="description-header">{{ stats['attempts'] }}</h5>
                      <span class="description-text">Total Attempts</span>
                    </div>
                  </div>
                </div>
                {% endif %}
                <div class="row">
                  <div class="col-sm-12">
                    <div class="description-block border-bottom">
                      <h5 class="description-header">{{ stats['num_backups'] }}</h5>
                      <span class="description-text">Number of backups</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-12">
                    <div class="description-block border-bottom">
                      <h5 class="description-header">{{ stats['num_submissions']  }}</h5>
                      <span class="description-text">Number of submissions</span>
                    </div>
                    <!-- /.description-block -->
                  </div>
              </div>
            </div>

            <!-- Begin Actions -->
            <div class="box">
              <div class="box-header with-border">
                <h3 class="box-title">Actions</h3>

                <div class="box-tools">
                  <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                </div>
              </div>
              <div class="box-body no-padding">
                <ul class="nav nav-pills nav-stacked">
                  <li> <a href="{{ url_for('.staff_submit_backup', cid=current_course.id, email=student.email, aid=assignment.id) }}" type="button">
                        <i class="fa fa-upload"></i> New Submission
                  </a></li>
                  <li> <a href="{{ url_for('.create_extension', cid=current_course.id, email=student.email, aid=assignment.id) }}" type="button">
                        <i class="fa fa-calendar"></i> Grant Extension
                  </a></li>
                  <li> <a href="{{ url_for('.assignment_timeline', cid=current_course.id, email=student.email,
                                           aid=assignment.id) }}" type="button">
                        <i class="fa fa-clock-o"></i> View Backup Timeline
                  </a></li>
                  <li> <a href="{{ url_for('.student_assignment_graph_detail', cid=current_course.id, email=student.email, aid=assignment.id)}}" type="button">
                        <i class="fa fa-bar-chart-o"></i> View Diff Graph
                  </a></li>
                </ul>
              </div>
              <!-- /.box-body -->
            </div>
            <!-- /. box -->

            <!-- Begin Group -->
            <div class="box">
              <div class="box-header with-border">
                <h3 class="box-title">Group</h3>
                <div class="box-tools pull-right">
                  <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                    <i class="fa fa-minus"></i></button>
                </div>
              </div>
              <div class="box-body no-padding">

              <ul class="nav nav-stacked">
                {% if assign_status.group %}
                    {% for member in assign_status.group.members %}
                    {% if member.user.email != student.email %}
                       <li><a href="{{ url_for('.student_assignment_detail',
                          cid=current_course.id, email=member.user.email, aid=assignment.id) }}">
                             {{ member.user.identifier }}
                              <span class="pull-right">
                              {% if member.status == 'active' %}
                                  <i class="fa fa-check-circle-o text-green" alt="Active Member"></i>
                              {% else %}
                                  <i class="fa fa-envelope text-blue" alt="Pending Member"></i>
                              {% endif %}
                          </span>
                              </a>
                      </li>
                    {% endif %}

                    {% endfor %}
                {% else %}
                    <li> <a href="#"> No Group
                    <span class="pull-right"><i class="fa fa-user-times text-gray" aria-hidden="true"></i> </span>
                    </a>
                    </li>
                {% endif %}
              </ul>

              </div>
              <!-- /.box-body -->
              <div class="box-footer">

                {% for member in assign_status.group.members %}
                  {% if member.user.email != student.email %}
                    {% call forms.render_form_bare(csrf_form, action_url=url_for('.staff_group_remove', cid=current_course.id, email=student.email,
                    aid=assignment.id), class_='') %}
                      <input class="hidden" name="target" value="{{ member.user.email }}" type="hidden"></input>
                      <button class="btn btn-default group-action btn-block hide-overflow"  type="submit" value="remove">
                          <i class="fa fa-minus-circle "></i>
                           Remove {{ member.user.email }}
                      </button>
                    {% endcall %}
                  {% endif %}
                  {% if loop.last %}
                     <hr>
                  {% endif %}
                {% endfor %}

                <label for="email">Add user to group</label>
                {% call forms.render_form(add_member_form, action_url=url_for('.staff_group_add', cid=current_course.id, email=student.email,
                    aid=assignment.id), action_text='Add User To Group', class_='form') %}
                    {{ forms.render_field(add_member_form.email, label_visible=email, placeholder='student@example.com', type='text') }}
                {% endcall %}

              </div>
              <!-- /.box-footer-->
            </div>
            <!-- /.box -->
          </div>

          <div class="col-md-9 col-sm-12">
            <!-- Default box -->
            <div class="box">
              <div class="box-header with-border">
                <h3 class="box-title">Backups/Submissions</h3>

                  <ul class="pagination pagination-sm no-margin pull-right">
                      {{ helpers.paginate(paginate, request.endpoint, page, params=request.view_args) }}
                  </ul>

              </div>
              <div class="box-body table-responsive no-padding">
                <table class="table table-hover table-striped">
                    <thead>
                      <th>Type</th>
                      <th>Created</th>
                      <th>Submitter</th>
                      <th>ID</th>
                      <th>Scores</th>
                      <th>Action</th>
                      <th>Flag</th>
                    </thead>
                    <tbody>
                        {%- for item in paginate.items %}
                        <tr>
                            <td> {{ 'Submission' if item.submit else 'Backup' }}
                            </td>
                            <td> {{ utils.local_time(item.created, current_course) }} </td>
                            <td>
                              {% if item.creator %}
                                  <a href="{{ url_for('.student_view', cid=current_course.id, email=item.creator.email) }}">{{ item.creator.email }}</a></br> on behalf of </br><a href="{{ url_for('.student_view', cid=current_course.id, email=item.submitter.email) }}">{{ item.submitter.email }}</a>
                                {% else %}
                                  <a href="{{ url_for('.student_view', cid=current_course.id, email=item.submitter.email) }}">{{ item.submitter.email }}</a>
                              {% endif %}  
                            </td>
                            <td> {% call helpers.backup_link(item.id) %}
                                 {% if item.id == assign_status.final_subm.id %}
                                     <i class="fa fa-star text-green" alt="Currently Grading"></i>
                                 {% endif %}
                                 {% endcall %}
                            </td>
                            <td>
                              {{ helpers.score_pills(item.active_scores) }}
                            </td>
                            <td>
                            <div class="btn-group">
                              <a href="{{ url_for('.grading', bid=item.id, diff='short') }}" class="btn btn-primary btn-flat">
                                  Grade
                              </a>
                            </div>
                            </td>
                            <td>

                            {% call forms.render_form_bare(csrf_form, action_url=url_for('.staff_flag_backup', cid=current_course.id, email=student.email,
                            aid=assignment.id), class_='') %}
                              <input class="hidden" name="bid" value="{{ item.hashid }}" type="hidden"></input>

                              {% if item.flagged %}
                                <button class="btn bg-orange btn-flat"  type="submit" value="remove">
                                      <i class="fa fa-flag-o" aria-hidden="true"></i> Remove Flag
                                </button>
                              {% else %}
                                <button class="btn btn-primary btn-flat"  type="submit" value="remove">
                                    Flag
                                </button>

                              {% endif %}
                            {% endcall %}


                              </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                  </table>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                  <div class="pull-left">
                      <h5 class="box-title"><span> Total: {{ paginate.total }} </span></h5>
                  </div>

                  <ul class="pagination pagination-sm no-margin pull-right">
                      {{ helpers.paginate(paginate, request.endpoint, page, params=request.view_args) }}
                  </ul>
              </div>
              <!-- /.box-footer-->
            </div>
            <!-- /.box -->
          </div>
        </div>

</section>
  <!-- </body> do not close body in template-->
{% endblock %}
